package com.ifinc.common.db;



import com.ifinc.common.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * User: luotao
 * Date: 12-4-16
 * Time: 17:03:00
 */

public class SqlGenUtils{

    public static String ConvertSql(String sql,Object... param) {
        StringBuffer str = new StringBuffer();
        sql = sql.trim();
        String[] ss  = sql.split("\\"+ StringUtils.STR_SQL_MARK);
        if(ss.length!=param.length)
            throw new RuntimeException("sql语句中的参数与param长度不相等");
        for(int i=0;i<ss.length;i++){
            if(param[i] instanceof String){
                str.append(ss[i]).append(StringUtils.STR_QUOT1).append(param[i]).append(StringUtils.STR_QUOT1);
            }else{
                str.append(ss[i]).append(param[i]) ;
            }
        }
        return str.toString();
    }

    public static class SQLGenerate{
        private String sql;

        private List<Object> objects = new ArrayList<Object>();

        public String getSql() {
            return sql;
        }

        public void setSql(String sql) {
            this.sql = sql;
        }

        public Object[] getObjects(){
           return objects.toArray();
        }
    }

    public SQLGenerate genInsert(String tableName) {
        System.out.println(1234567890);
        return null;
    }

    public SQLGenerate genSelect(String tableName){
        return null;
    }

    public SQLGenerate genUpdate(String tableName){
        return null;
    }

    public SQLGenerate genDelete(String tableName){
        return null;
    }
}
